package com.jyy.prefabricated.service.impl;

import com.jyy.prefabricated.dto.BatchDto;
import com.jyy.prefabricated.entity.ExamCourse;
import com.jyy.prefabricated.mapper.ExamCourseMapper;
import com.jyy.prefabricated.service.ExamCourseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考试关联课程表(ExamCourse)表服务实现类
 *
 * @author makejava
 * @since 2021-06-01 15:14:01
 */
@Service("examCourseService")
public class ExamCourseServiceImpl implements ExamCourseService {
    @Resource
    private ExamCourseMapper examCourseMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ExamCourse queryById(Integer id) {
        return this.examCourseMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ExamCourse> queryAllByLimit(int offset, int limit) {
        return this.examCourseMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param examCourse 实例对象
     * @return 实例对象
     */
    @Override
    public ExamCourse insert(ExamCourse examCourse) {
        this.examCourseMapper.insert(examCourse);
        return examCourse;
    }

    /**
     * 修改数据
     *
     * @param examCourse 实例对象
     * @return 实例对象
     */
    @Override
    public ExamCourse update(ExamCourse examCourse) {
        this.examCourseMapper.update(examCourse);
        return this.queryById(examCourse.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.examCourseMapper.deleteById(id) > 0;
    }

    @Override
    public int batchUpdateDeleted(BatchDto dto) {
        return examCourseMapper.batchUpdateDeleted(dto);
    }

    @Override
    public List<ExamCourse> queryList(ExamCourse examCourse) {
        examCourse.setDeleted(false);
        return examCourseMapper.queryAll(examCourse);
    }
}
